package com.rljk.taskschedule;

import com.rljk.redis.RedisService;
import com.rljk.service.UserManager;
import com.rljk.service.impl.AssetsService;
import com.rljk.service.impl.TrustSqlService;
import com.rljk.service.impl.WealthService;
import com.rljk.utils.SnowIdUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Author:   YASUO
 * Date:     2018/7/30 17:08
 * Description:定时任务
 */
@Component
@Slf4j
public class ScheduleService {

    @Resource(name = "userService")
    private UserManager userService;

    @Resource(name = "assetsService")
    private AssetsService assetsService;

    @Resource(name = "trustSqlService")
    private TrustSqlService trustSqlService;

    @Autowired
    RedisService redisService;

    @Resource(name = "wealthService")
    private WealthService wealthService;



    //每两小时启动
    //@Scheduled(cron = "*/5 * * * * ?")
    //@Scheduled(cron = "0 0/10 * * * ?")//每10分钟启动
    //@Scheduled(cron = "0 0 0,13,18,21 * * ?")// 每天的0点、13点、18点、21点都执行一次
    @Scheduled(cron = "0 0 * * * ?")// 每天每1小时触发一次
    public void produceXW(){
        log.info("每两小时启动");
        try {
            Map<String,String> map = new HashMap<>();
            List<String> allUserId = userService.getAllUserId();
            for (String id : allUserId) {
//                for (int i = 0; i < 200; i++) {
                    log.info("id:" + id);
                    String WEALTH_ID = SnowIdUtil.getSnowId();
                    redisService.setex(id + "_" + WEALTH_ID, "0.0022", 60 * 60 * 24 * 2);//过期时间2天
//                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
